package cn.stylefeng.guns.modular.business.app.controller;

import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.modular.business.app.RyController;
import cn.stylefeng.guns.modular.business.custom.constant.PublicCommon;
import cn.stylefeng.guns.modular.business.frequency.banner.entity.Banner;
import cn.stylefeng.guns.modular.business.frequency.banner.service.BannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图管理
 * @Author liwenlong
 */
@CrossOrigin
@RestController
@RequestMapping("/api/banner")
public class ApiBannerController extends RyController {


    @Autowired
    private BannerService bannerService;


    /**
     *  获取所有banner
     *
     * @return
     */
    @PostMapping("/list")
    public ResponseData list() {
        List<Banner> list = bannerService.list(new QueryWrapper<Banner>().lambda()
                .eq(Banner::getDelFlag, PublicCommon.启用).orderByAsc(Banner::getSort));
        return ResponseData.success(list);
    }


    /**
     * 获取banner详情
     *
     * @param id
     * @return
     */
    @PostMapping("/getOne")
    public ResponseData getOne(@RequestParam("id") Long id) {
        Banner byId = bannerService.getById(id);
        return ResponseData.success(byId);
    }

}
